# coding=utf8
import numpy as np
import pandas as pd


class Preliminary:

    pass


def task():
    df82 = pd.read_csv("stu82.csv", header=0, delimiter=',', encoding='utf8')
    # df82 = df82.astype({'sno': str})
    print(df82.info())
    score1_stat = df82.score1.median(), df82.score1.var(), df82.score1.std()
    score2_stat = df82.score2.median(), df82.score2.var(), df82.score2.std()
    out = df82.describe()
    score2_quantile1 = out['score2']['25%']
    score2_quantile3 = out['score2']['75%']

    print(out.keys())
    print(
        ">>> df82\n"
        f"{df82}\n"
        f">>> df82.describe()\n"
        f"{out}"
    )
    print("Score1中位数、方差、标准差 = {:.2f}, {:.2f}, {:.2f}".format(*score1_stat))
    print("Score2中位数、方差、标准差 = {:.2f}, {:.2f}, {:.2f}".format(*score2_stat))
    print(
        f"Score2第一分位数 = {score2_quantile1}\n"
        f"Score2第三分位数 = {score2_quantile3}\n"
    )


def training1():
    df82 = pd.read_csv("stu82.csv", header=0, delimiter=',', encoding='utf8')
    # df82 = df82.astype({'sno': str})
    print(df82.info())
    desc = df82.describe()
    score1_stat = [desc.loc['mean', 'score1'], desc.loc['std', 'score1'], desc.loc['max', 'score1']]
    score2_stat = [desc.loc['count', 'score2'], desc.loc['min', 'score1'], desc.loc['50%', 'score1']]
    score2_quantile1 = desc['score2']['25%']
    score2_quantile3 = desc['score2']['75%']

    print(
        ">>> df82\n"
        f"{df82}\n\n"
        f">>> df82.dtypes\n"
        f"{df82.dtypes}\n\n"
        f">>> df82.describe()\n"
        f"{desc}\n"
    )
    print("Score1均值、标准差、最大值 = {:.2f}, {:.2f}, {:.2f}".format(*score1_stat))
    print("Score2中位数、方差、标准差 = {:.2f}, {:.2f}, {:.2f}".format(*score2_stat))
    print(
        f"Score2第1四分位数 = {score2_quantile1}\n"
        f"Score2第3四分位数 = {score2_quantile3}\n"
    )


def training2():
    df82 = pd.read_csv("stu82.csv", header=0, delimiter=',', encoding='utf8')
    # df82 = df82.astype({'sno': str})
    print(df82.info())
    desc = df82.describe(percentiles=(0.15, 0.25, 0.3, 0.7))
    score1_stat = [desc.loc['15%', 'score1'], desc.loc['30%', 'score1'], desc.loc['70%', 'score1']]
    score2_stat = [desc.loc['max', 'score2'], desc.loc['min', 'score1'], desc.loc['25%', 'score1']]

    print(
        ">>> df82\n"
        f"{df82}\n\n"
        f">>> df82.dtypes\n"
        f"{df82.dtypes}\n\n"
        f">>> df82.describe()\n"
        f"{desc}\n"
    )
    print("Score1均值、标准差、最大值 = {:.2f}, {:.2f}, {:.2f}".format(*score1_stat))
    print("Score2中位数、方差、标准差 = {:.2f}, {:.2f}, {:.2f}".format(*score2_stat))


if __name__ == '__main__':
    # task()
    # training1()
    training2()
